$(function () {
    initLayerDate("#96k_begTime",false);
    initLayerDate("#96k_endTime",false);
    //---------加载时间---开始
    initIndexTime();
    //---------加载时间---结束

    //-----加载基本数据统计--开始
    function watchBaseCount(callback) {
        $.ajax({
            url:baseloaction +'/admin/count/watchBaseCount',
            type:'post',
            dataType:'json',
            success:function (result) {
                callback(result.entity);
            }
        });
    }
    watchBaseCount(function (data) {
        var obj = data.v96kData;
        var use_flow = obj.use_flow;//已使用流量
        use_flow = bToG(use_flow);//换成G
        $("#use_flow").text(parseFloat(use_flow).toFixed(2));

        var flow = obj.flow;//总流量
        flow = bToG(flow);//换成G
        var subFlow = flow - use_flow;
        $("#sub_flow").text(parseFloat(subFlow).toFixed(2));
        var use_space = obj.use_space;//已使用空间
        use_space = bToG(use_space);//换成G

        var space = obj.space;//总空间
        space = bToG(space);//换成G

        //计算剩余空间
        var  subSpace = space - use_space;
        subSpace = parseFloat(subSpace).toFixed(3);
        $("#sub_space").text(subSpace);
        //视频节数
        $("#video_num").text(obj.video_num);
        //直播场数
        $("#room_num").text(obj.room_num);
    });
    //-----加载基本数据统计--结束

    //把B转换成G
    function bToG(dataNum) {
        var _dataNum = bToM(dataNum) / 1024;//换成G
        return _dataNum;
    }
    //把B转换成G
    function bToM(dataNum) {
        var _dataNum = parseInt(dataNum) /1024 /1024;//换成M
        return _dataNum;
    }

    $('body').on('click','.dua',function(){
        var params = $('#96ke-form').serializeJSON();
        if(params.begTime==""){
            icModale(0, "请选择开始时间");
            return;
        }
        if(params.endTime==""){
            icModale(0, "请选择结束时间");
            return;
        }
        get96KMonthCountDataTo();
    });
    //===================当月观看流量曲线===开始
    /**
     * 获取96K统计数据
     * @return {*}
     */
    function get96KMonthCountData(callback) {
        var params = $('#96ke-form').serializeJSON();
        params = JSON.stringify(params);
        $.ajax({
            url:baseloaction +'/admin/count/query96KMonthDataCount',
            type:'post',
            dataType:'json',
            data:params,
            async:false,
            contentType:'application/json;charset=utf-8',
            success:function (result) {
                if(result.success==true){
                    callback(result.entity);
                }
            }
        });
    }
    get96KMonthCountDataTo();
   function   get96KMonthCountDataTo(){
    get96KMonthCountData(function (data) {
        if(data!=null){
            var dataList = new Array();
            var nameList = new Array();
            var max = 0;
            for(var i=0;i<data.length;i++){
                var obj = data[i];
                var flow = obj.flow;
                flow = bToM(flow);
                if(flow> max){
                    max = flow;
                }
                dataList.push(parseFloat(flow).toFixed(2));
                nameList.push(obj.day+"日");
            }
            max = parseFloat(max).toFixed(2)
            var watchFlowChart = echarts.init(document.getElementById("watch-flow-echarts-line-chart")),
                colors = ['#62A1FE', '#4ECE39', '#675bba'];
            var watchFlowChartOption = {
                color: colors,
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'cross',
                        crossStyle: {
                            color: '#999'
                        }
                    }
                },
                toolbox: {
                    feature: {
                        dataView: {show: true, readOnly: false},
                        magicType: {show: true, type: ['line', 'bar']},
                        restore: {show: true},
                        saveAsImage: {show: true}
                    }
                },
                legend: {
                    data:['观看流量']
                },
                xAxis: [
                    {
                        type: 'category',
                        data:nameList,
                        axisPointer: {
                            type: 'shadow'
                        }
                    }
                ],
                yAxis: [
                    {
                        type: 'value',
                        name: '观看流量',
                        min: 0,
                        max: max,
                        interval: 50,
                        axisLabel: {
                            formatter: '{value} M'
                        }
                    }
                ],
                series: [
                    {
                        name:'观看流量',
                        type:'line',
                        data:dataList
                    }
                ]
            };
            watchFlowChart.setOption(watchFlowChartOption);
            $(window).resize(watchFlowChart.resize);
        }
    });
   }
    //===================当月观看流量曲线===结束

    //====专业/科目观看量 TOP 10=========开始===
    //获取视频观看量 TOP10的专业/科目
    function getSubjectVideoTopCountData(callback) {
        $.ajax({
            url:baseloaction +'/admin/count/queryTopSubjectPlayCount',
            type:'post',
            dataType:'json',
            async:false,
            success:function (result) {
                if(result.success==true){
                    callback(result.entity);
                }
            }
        });
    }
    getSubjectVideoTopCountData(function (dataList) {
        var nameList = new Array();
        var numList = new Array();
        if(dataList!=null){
            for(var i=0;i<dataList.length;i++){
                var obj = dataList[i];
                numList.push(obj.subjectNum);
                var subjectList = obj.subjectList;
                var subjectNames = '';
                $.each(subjectList,function (index,subject) {
                    if(index < subjectList.length-1){
                        subjectNames += subject.subjectName + "/";
                    }else{
                        subjectNames += subject.subjectName;
                    }
                });
                nameList.push(subjectNames);
            }
        }
        var orderTop10Subject = echarts.init(document.getElementById("subject-look-echarts-line-chart")),
            colors = ['#62A1FE', '#4ECE39', '#675bba'];
        var lineoption = {
            title: {
                text: '专业/项目录播视频播放量TOP 10',
                subtext: ''
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                }
            },
            legend: {
                data: ['观看量']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: {
                type: 'value',
                boundaryGap: [0, 0.01]
            },
            yAxis: {
                type: 'category',
                data: nameList
            },
            series: [
                {
                    name: '观看量',
                    type: 'bar',
                    data: numList
                }
            ]
        };
        orderTop10Subject.setOption(lineoption);
        $(window).resize(orderTop10Subject.resize);
    });
    //====专业/科目观看量 TOP 10=========结束===

    //访问量最高的前 10场 直播===========开始===
    function getTop10LiveCountData(callback) {
        $.ajax({
            url:baseloaction +'/admin/count/queryToLiveCount',
            type:'post',
            dataType:'json',
            async:false,
            success:function (result) {
                if(result.success==true){
                    callback(result.entity);
                }
            }
        });
    }
    getTop10LiveCountData(function (dataList) {
        if(dataList != null){
            var nameList = new Array();
            var numList = new Array();
            for(var i=0;i < dataList.length ; i++){
                var obj = dataList[i];
                nameList.push(obj.name);
                numList.push(obj.liveNum);
            }
            var liveTop10 = echarts.init(document.getElementById("live-look-echarts-line-chart")),
                colors = ['#62A1FE', '#4ECE39', '#675bba'];
            var lineoption = {
                title: {
                    text: '访问量最高的前 10场 直播',
                    subtext: ''
                },
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow'
                    }
                },
                legend: {
                    data: ['访问量']
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: {
                    type: 'value',
                    boundaryGap: [0, 0.01]
                },
                yAxis: {
                    type: 'category',
                    data: nameList
                },
                series: [
                    {
                        name: '访问量',
                        type: 'bar',
                        data: numList
                    }
                ]
            };
            liveTop10.setOption(lineoption);
            $(window).resize(liveTop10.resize);
        }
    });
    //访问量最高的前 10场 直播===========结束===
});